package com.wangchao.administrator.zenmechi.ui.stepactivity;

import android.content.Context;
import android.util.Log;

import com.wangchao.administrator.zenmechi.bean.stepbean.StepBean;
import com.wangchao.administrator.zenmechi.bean.stepbean.StepFoodmaterialsBean;
import com.wangchao.administrator.zenmechi.bean.stepbean.StepIngredientsListsBean;
import com.wangchao.administrator.zenmechi.bean.stepbean.StepResultBean;

import java.util.ArrayList;
import java.util.List;

import rx.Subscriber;

/**
 * Created by Administrator on 2016/10/17.
 */
public class StepActivityPresenter implements StepActivityContract.Presenter {

    private StepActivityContract.View view;
    private StepActivityContract.Model model;

    private String itemId;
    private StepResultBean resultBean;
    private List<StepFoodmaterialsBean> foodmaterialsBeen = new ArrayList<>();
    private MyAdapterForMaterial adapterForMaterial;
    private List<StepIngredientsListsBean> ingredientsListsBeen = new ArrayList<>();
    private MyAdapterForingredients adapterForingredients;

    public StepActivityPresenter(StepActivityContract.View view) {
        this.view = view;
        this.model = new StepActivityModel();
    }

    @Override
    public void getStep(final Context context) {
        itemId = view.getItemId();
        model.getStep(itemId, new Subscriber<StepBean>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                Log.i("tag","----------"+e.toString());
            }

            @Override
            public void onNext(StepBean bean) {
                resultBean = bean.getResult();
                view.initScrollView(resultBean);
                foodmaterialsBeen = resultBean.getFoodmaterials();
                if (foodmaterialsBeen!=null&&foodmaterialsBeen.size()!=0){
                    adapterForMaterial = new MyAdapterForMaterial(context,foodmaterialsBeen);
                    view.initMaterials(adapterForMaterial);
                }
                ingredientsListsBeen = resultBean.getIngredients_lists();
                adapterForingredients = new MyAdapterForingredients(context,ingredientsListsBeen);
                view.initIngredients(adapterForingredients);
            }
        });
    }
}
